# cookie登录
from selenium import webdriver


def cookieLogin(username):
    wd = webdriver.Chrome('../浏览器驱动/chromedriver.exe')
    wd.minimize_window()
    # 打开登录页面
    wd.get('https://bilibili.com/')

    # 清除所有cookie
    wd.delete_all_cookies()

    # 获取用户cookie
    path = '../cookie/{}.txt'.format(username)
    with open(path, 'r') as f:
        cookieslist = eval(f.read().strip())

    # 遍历添加cookie
    for cookie in cookieslist:
        wd.add_cookie(cookie)

    wd.get('https://www.bilibili.com/')
    return wd
